import {
  Router,
  Route,
  IndexRoute,
  hashHistory
} from 'react-router';
import Refast, {
  LogicRender
} from 'refast';
import {
  Component
} from 'react';
import {
  render
} from 'react-dom';
import FastClick from 'fastclick';
import {
  Toast,
  Dialog
} from 'saltui';

import {
  isDev
} from 'variables';
import PageHome from 'pages/home';
import PageDemo from 'pages/demo';

import PostPage from 'pages/post/page';
import PostEdit from 'pages/post/edit';
import UnPostEdit from 'pages/post/UnEdit';
import PostLabel from 'pages/post/label';
import PostBoardMove from 'pages/post/move';
import PostReply from 'pages/post/reply';
import PostView from 'pages/post/view';
import PostEditView from 'pages/post/editView';
import PostComment from 'pages/post/comment';

import MyPage from 'pages/my/page';
import MyRemind from 'pages/my/remind';
import MyRemindType from 'pages/my/remindType';
import MySend from 'pages/my/send';
import MyDraft from 'pages/my/draft';
import MyCheck from 'pages/my/check';
import MyCollect from 'pages/my/collect';
import Rejection from 'pages/post/unCheck';


import BoardPage from 'pages/board/page';
import BoardView from 'pages/board/view';
import BoardNavigate from 'pages/board/navigate';

import DB from 'db';
import './app.less';

const customHistory = hashHistory;

if (isDev && window.chrome && window.chrome.webstore) { // This is a Chrome only hack
  // see https://github.com/livereload/livereload-extensions/issues/26
  setInterval(() => {
    document.body.focus();
  }, 200);
}

// bind fastclick
FastClick.attach(document.body);

// 这里使用 use 来配置 Refast
// Refast 文档 https://recore.github.io/refast-docs/
Refast.use('fn', {
  toast: Toast,
  dialog: Dialog,
  DB,
  history: customHistory,
});

const Loading = () => <div className="kuma-loading" />;
const Empty = () => <div>暂无数据</div>;

// 修改 LogicRender 增加默认配置
// 用来自定义Loading和Empty的样式
LogicRender.defaultProps.Empty = Empty;
LogicRender.defaultProps.Loading = Loading;

class App extends Component {
  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }
}

render(
  <Router history={customHistory}>
    <Route name="app" path="/" component={App}>
      <IndexRoute component={PostPage} />
      <Route path="home" component={PageHome} />
      <Route path="demo" component={PageDemo} />
      <Route path="post" >
        <Route path="page" component={PostPage} />
        <Route path="unCheck(/:id)(/:route)" component={Rejection} />
        <Route path="edit(/:postId)(/:checkStatus)(/:author)(/:pagetype)(/:isAuthor)" component={PostEdit} />
        <Route path="unEdit(/:postId)(/:checkStatus)(/:author)(/:pagetype)(/:isAuthor)" component={UnPostEdit} />
        <Route path="label(/:postId)" component={PostLabel} />
        <Route path="move(/:postId)(/:boardId)" component={PostBoardMove} />
        <Route path="view(/:id)(/:checkStatus)(/:isModerator)(/:author)(/:isAuthor)(/:isCheck)" component={PostView} />
        <Route path="editView(/:id)(/:checkStatus)(/:isModerator)(/:author)(/:isAuthor)(/:isCheck)" component={PostEditView} />
        <Route path="reply(/:isShowAnonymity)(/:postId)(/:boardId)(/:id)(/:otherId)(/:author)(/:checkStatus)(/:comments)(/:postLevel)(/:receiverId)(/:isShowPetname)" component={PostReply} />
        <Route path="reply1(/:isShowAnonymity)(/:postId)(/:boardId)(/:isShowPetname)" component={PostReply} />
        <Route path="comment(/:id)(/:num)(/:author)(/:authorName)(/:createdDate)(/:isAnonymity)(/:image)(/:boardStatus)(/:boardIsDelete)" component={PostComment} />
      </Route>
      <Route path="board" >
        <Route path="navigate" component={BoardNavigate} />
        <Route path="page(/:boardId)(/:replyCount)(/:postCount)(/:boardName)(/:attIdJson)" component={BoardPage} />
        <Route path="view(/:boardId)" component={BoardView} />
      </Route>
      <Route path="my" >
        <Route path="page(/:page)" component={MyPage} />
        <Route path="remind(/:remindPage)" component={MyRemind} />
        <Route path="remindType" component={MyRemindType} />
        <Route path="send" component={MySend} />
        <Route path="draft" component={MyDraft} />
        <Route path="check" component={MyCheck} />
        <Route path="collect" component={MyCollect} />
      </Route>
    </Route>
  </Router>,
  document.getElementById('App'),
);